$def with (page, num_found, results_per_page=20)

$ pages = ceil(num_found / results_per_page)
$if pages != 1:
    $ pages_in_set = 10
    $ half = pages_in_set // 2
    $if pages < pages_in_set:
        $ first_page_in_set = 1
        $ last_page_in_set = pages
    $elif page < half:
        $ first_page_in_set = 1
        $ last_page_in_set = min((pages_in_set, pages))
    $elif page > (pages-half):
        $ first_page_in_set = max((pages-pages_in_set, 1))
        $ last_page_in_set = pages
    $else:
        $ first_page_in_set = max((page-half, 1))
        $ last_page_in_set = page+half

    <div class="pagination">
    $if page != 1:
        <a href="$changequery(page=None)" class="ChoosePage" data-ol-link-track="Pager|First">&laquo;&nbsp;$_('First')</a>
        <a href="$changequery(page=page-1)" class="ChoosePage" data-ol-link-track="Pager|Previous">&lt;&nbsp;$_('Previous')</a>
    $for p in range(first_page_in_set, last_page_in_set+1):
        $if p == page:
            <span class="this">$p</span>
        $else:
            <a href="$changequery(page=p)" class="ChoosePage" data-ol-link-track="Pager|Offset$(p - page)">$p</a>
    $if last_page_in_set != pages:
        $if last_page_in_set != pages-1:
            <span class="ellipsis">...</span>
        <a href="$changequery(page=pages)" class="ChoosePage" data-ol-link-track="Pager|LastPage">$pages</a>
    $if page < pages:
        <a href="$changequery(page=page+1)" class="ChoosePage" data-ol-link-track="Pager|Next">$_('Next')&nbsp;&gt;</a>
    </div>
